package org.spbsu.apco.server.monitoring.prediction.impl;

import org.spbsu.apco.common.data.core.DurationEstimable;
import org.spbsu.apco.common.properties.ApplicationPropertiesManager;
import org.spbsu.apco.common.properties.PropertyKey;
import org.spbsu.apco.common.task.core.BaseTask;
import org.spbsu.apco.common.task.core.Ticket;
import org.spbsu.apco.common.task.core.WaitTask;
import org.spbsu.apco.server.monitoring.prediction.TicketDurationPredictor;

/**
 * User: ortemij
 * Date: 04.01.13
 * Time: 21:12
 */
public class DummyTicketDurationPredictor implements TicketDurationPredictor {

    private int waitTaskDuration = Integer.valueOf(ApplicationPropertiesManager.getProperty(PropertyKey.WAIT_TASK_DURATION));
    private int defaultDuration = Integer.valueOf(ApplicationPropertiesManager.getProperty(PropertyKey.DEFAULT_TASK_DURATION));

    @Override
    public int predictDuration(Ticket ticket, String clientId) {
        final BaseTask task = ticket.getTask();
        if (task instanceof DurationEstimable) {
            return ((DurationEstimable) task).estimateDuration(ticket.getArguments());
        }
        if (task instanceof WaitTask) {
            return waitTaskDuration;
        }
        return defaultDuration;
    }

    public void setWaitTaskDuration(int waitTaskDuration) {
        this.waitTaskDuration = waitTaskDuration;
    }

    public void setDefaultDuration(int defaultDuration) {
        this.defaultDuration = defaultDuration;
    }
}
